<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          size="mini"
          icon="el-icon-refresh"
          plain
          @click="handleQuery"
        >刷新</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          size="mini"
          icon="el-icon-delete"
          plain
          :disabled="multiple"
          @click="handleTruncate"
          v-hasPermi="['toolbox:database:truncate']"
        >清空</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="tableList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" align="center" width="55"/>
      <el-table-column label="表名" align="left" prop="name"/>
      <el-table-column label="备注" align="left" prop="comment" :show-overflow-tooltip="true"/>
      <el-table-column label="数据行数" align="left" prop="rows"/>
      <el-table-column label="数据大小" align="left" prop="dataSize"/>
      <el-table-column label="数据引擎" align="left" prop="engine"/>
      <el-table-column label="字符集" align="left" prop="collation"/>
      <el-table-column label="创建时间" align="center">
        <template v-slot="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import {selectTableList} from "@/api/toolbox/database";

export default {
  name: "Database",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 数据列表
      tableList: [],
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
    };
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询数据表 */
    getList() {
      this.loading = true;
      selectTableList().then(response => {
        this.tableList = response.data;
        this.loading = false;
      });
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.name)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 刷新按钮操作 */
    handleQuery() {
      this.getList();
    },
    /** 清空按钮操作 */
    handleTruncate() {
      console.log("truncate")
    },
  }
};
</script>
